package com.mars.tukuan.rpc.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mars.base.common.exception.AppException;
import com.mars.base.common.utils.Paginator;
import com.mars.base.service.support.BaseService;
import com.mars.tukuan.dao.mapper.CarMapper;
import com.mars.tukuan.dto.CarVo;
import com.mars.tukuan.entity.Car;
import com.mars.tukuan.rpc.api.CarService;

@Service
public class CarServiceImpl extends BaseService<Car, Long> implements CarService {
	
	@Autowired
	private CarMapper mapper ;
	
	@Override
	public Car insertSelective(Car entity) throws AppException {
		entity.setCarCity(entity.getCarCity().toUpperCase());
		entity.setCarNum(entity.getCarNum().toUpperCase());
		entity.setCarFullNum(entity.getCarArea()+entity.getCarCity()+entity.getCarNum());
		return super.insertSelective(entity);
	}
	
	@Override
	public Car updateSelective(Car entity) throws AppException {
		entity.setCarCity(entity.getCarCity().toUpperCase());
		entity.setCarNum(entity.getCarNum().toUpperCase());
		entity.setCarFullNum(entity.getCarArea()+entity.getCarCity()+entity.getCarNum());
		return super.updateSelective(entity);
	}

	@Override
	public PageInfo<Car> selectPageByCarState(Paginator paginator, CarVo entity) {
		PageHelper.startPage(paginator.getPage(), paginator.getRows()) ;
		Page<Car> page = this.mapper.selectPageByCarState(paginator, entity) ;
		
		return new PageInfo<Car>(page) ;
	}

	@Override
	public List<Car> searchCarByNum(String num) {
		return this.mapper.searchCarByNum(num);
	}

	@Override
	public void updateCheckTime(Long id) {
		this.mapper.updateCheckTime(id);
	}

	@Override
	public PageInfo<Car> selectPageByHarm(Paginator paginator, CarVo entity) {
		PageHelper.startPage(paginator.getPage(), paginator.getRows()) ;
		Page<Car> page = this.mapper.selectPageByHarm(paginator, entity) ;
		
		return new PageInfo<Car>(page) ;
	}

	@Override
	public PageInfo<Car> myCarState(Paginator paginator, CarVo entity) {
		PageHelper.startPage(paginator.getPage(), paginator.getRows()) ;
		Page<Car> page = this.mapper.myCarState(paginator, entity) ;
		
		return new PageInfo<Car>(page) ;
	}

	@Override
	public PageInfo<Car> selectPageByCarCheck(Paginator paginator, CarVo entity) {
		PageHelper.startPage(paginator.getPage(), paginator.getRows()) ;
		Page<Car> page = this.mapper.selectPageByCarCheck(paginator, entity) ;
		
		return new PageInfo<Car>(page) ;
	}

}
